<?php

class TypeController extends CommonController{
	private $_model;
	public function __init(){
		$this->_model=K('Type');
	}
	
	
	
	public function index(){
		$data = $this->_model->get_all_type(null,true);
		//分配page变量
		$this->assign('page',$data['page']);
		//在分页分配完成之后，$data['page']就没用了
		//如果继续留着循环就会出问题
		unset($data['page']);
		$this->assign('data',$data);
		
		$this->display();
	}
	
	
	public function addattr(){
		if(IS_POST){
			$this->_model->add_type();
			$this->success('添加成功',U('index'));
		}		
		$this->display();
	}
	//编辑类型
	public function editattr(){
		if(IS_POST){
			$this->_model->edit_type(array('id'=>Q('post.id',0,'intval')));
			$this->success('修改成功',U('Type/index'));
		}
		//获取旧数据
		$olddata = $this->_model->get_one_type(array('id'=>Q('id',0,'intval')));
		$this->assign('olddata',$olddata);
		
		$this->display();
	}
	//删除类型
	public function del(){
		if($this->_model->delete_type(Q('get.id',0,'intval')));
			$this->success('删除成功');
//		echo Q('post.id',0,'intval');
		
		$this->error($this->_model->error);
	}
	
	
	
	
	
	
	
}//end
